<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <script src="${ctxStatic}/js/style.js"></script>
        <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
        <link rel="stylesheet" href="${ctxStatic}/css/list.css">
        
        <script type="text/javascript">
			$(document).ready(function(){
				 	
	            // 下拉选框带搜索功能
	            $("#materialTypeCd,#materialUseType,#materialOgnizationId,#brandID").select2();
				searchListForm();
				
			});	
	               
	    	function searchListForm(t) {
	    		var params = $("#searchForm").serialize();
	    		$("#activity_pane").showLoading();
	    		var url = "";
	    		if (t == "cloud") {
	    			url = "${ctx}/material/stock/searchList?pageNo="+$("#pageNum").val();
				}else{
					url = "${ctx}/material/stock/searchList";
				}
	    		$.post(url,params, function(result) {
	    			var listHtml = result["material"];
	    			var pageHtml = result["page"];
	    			$("#listHtml").html(listHtml);
	    			$("#paging").html(pageHtml);
	    			$("#activity_pane").hideLoading();
	    		}, 'json');
	    	}
	    	
	        
	        //重置
	        function clean(){
                $("input").val("");
                $('#materialTypeCd,#materialUseType').val('');
                $("#materialTypeCd,#materialUseType").select2(); 
	            searchListForm();
	        }
	        
	        $(document).keydown(function(event){
	        	if(event.keyCode == 13){
	        		searchListForm();
	        	}
	        });
	        //客户品牌联动
	        function materialOgnizationFun() {
	        	var id = "${material.id}";
	        	var brandID = "${material.brandID}";
	        	var materialOgnizationId=$("#materialOgnizationId").find("option:selected").val();    	
	        	var pleaseSelect = '<option value="">' + '<spring:message code="style_pleaseSelect" />'+'</option>';
	        	param={"materialOgnizationId":materialOgnizationId,"id":id,"brandID":brandID};
	        	$.post("${ctx}/material/stock/findBrand",param,function(result){            
	        		 var html = "";
	                 var brandList = result["brandNameCnList"];
	                 $(brandList).each(function(i,e) {
	                     html += "<option value='"+e.apBrandId+"'>"
	                         + e.brandCn
	                         + "</option>";
	     			});
	                 $("#brandID").html(pleaseSelect+html);
	                 $("#brandID").select2();
	            },'json');
	    	}
	        
	        // 同步到平台
	        function synToMTM(){
	        	$("#activity_pane").showLoading();
	        	$.post("${ctx}/material/stock/synToMTM","",function(result){          
	        		if(result == "true"){
	        			alert("同步成功:)");
	        		}else{
	        			alert("同步失败，请联系管理员！");
	        		}
	        		
	        		$("#activity_pane").hideLoading();
	            },'json');
	        }
	        
        </script> 
    </head>
    <body>
    <c:set value="<%=ResourcesUtil.getConfig(\"material_Category\")%>" var="materialCategory" />
    <c:set value="<%=ResourcesUtil.getConfig(\"material_UseType\")%>" var="useType" />
    <form id="searchForm">
    <input type="hidden" id="pageNum" value=""/>
 <div class="listArea" id="activity_pane">
	<div class="listBg">
        <div class="searchArea clearfix">
            <div class="searchLeft clearfix" style="width: 1450px;">
                	<div id="ognizationHtml" class="searchInp clearfix">
                        <!-- 客	户 -->
                        <p><spring:message code="material_showMateial_ognizationList"/></p>
                        <select style="width:130px" id="materialOgnizationId" name="materialOgnizationId" onchange="materialOgnizationFun();" data-rule-required="true"  data-msg-required="<spring:message code="material_pleaseChoosedOgnization"/>">
	                 <option value=""><spring:message code="material_pleaseChoosed"/></option>
	                 <c:forEach items="${material.ognizationList}" var="ognizationInfo">
	                    <option data-value="${ognizationInfo.ognizationType}" <c:if test="${material.materialOgnizationId eq ognizationInfo.id}">selected="selected"</c:if> value="${ognizationInfo.id}" > 
	                       ${ognizationInfo.ognizationName}
	                    </option>
	                 </c:forEach>
	              </select>
                    </div>
                    <div id="brandHtml" class="searchInp clearfix">
                        <p class="tit"><spring:message code="material_showMateial_brandName"/></p>                
                    <select class="width-125px" style="width:125px" id="brandID" name="brandCn">
                 			<option value=""><spring:message code="material_pleaseChoosed"/></option>
                    </select>
                    </select>
                    </div>
                    <div class="searchInp clearfix">
                        <!-- 物料类别 -->
                        <p><spring:message code="material_materialType"/></p>
                        <select class="width-125px" id="materialTypeCd" name="materialTypeCd">
                            <option value=""><spring:message code="material_pleaseChoosed"/></option>
	                        <c:forEach items="${fns:getDictList(materialCategory)}"   var="category">
	                            <option  <c:if test="${fn:split(material.materialTypeCd,'-')[1] eq category.itemValue}">selected="selected"</c:if> value="${category.itemCode}-${category.itemValue}" > 
	                                ${category.itemName}
	                            </option>
	                        </c:forEach>
                        </select>
                	</div>
                    <div class="searchInp clearfix">
                        <!-- 物料编码 -->
                        <p><spring:message code="material_showMateial_code"/></p>
                        <input type="text"  id="materialCode"  name="materialCode"  value="" >
                    </div>
                    <div class="searchInp clearfix">
                        <!-- 物料名称 -->
                        <p><spring:message code="material_showMateial_name"/></p>
                        <input type="text"  id="materialNameCn"  name="materialNameCn"  value="" >
                    </div>
                    <div class="searchInp clearfix">
                        <!-- 物料成分 -->
                        <p><spring:message code="material_composition"/></p>
                        <input type="text" style="width:80px" id="materialComposition"  name="materialComposition"  value="" >
                    </div>
                    <div class="searchInp clearfix">
                        <!-- 描述 -->
                        <p><spring:message code="material_remarks"/></p>
                        <input type="text" style="width:80px" id="remarks"  name="remarks"  value="" >
                    </div>
                    
                </div>
                <div class="searchRight clearfix">
                	<%-- <button type="button" onclick="popup('1150px','680px','${ctx}/common/material/list')">test</button> --%>
                    <shiro:hasPermission name="material:stock:edit">
                    <!-- 同步到平台-->
		            <button type="button" class="btn-js"  onclick="synToMTM();">同步到平台</button>
                	<%-- <!-- 入出库导入 -->
		            <button type="button" class="btn-js"  onclick="popup('500px','150px','${ctx}/material/stock/uploadExcel');"><spring:message code="material_inoutboundImport"/></button> --%>
		            <!-- 物料导入 -->
		            <button type="button" class="btn-js"  onclick="popup('500px','150px','${ctx}/material/stock/uploadExcelFile');"><spring:message code="material_materialImport"/></button>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="material:stock:view">
                    <button type="button" id="searchBtn" onclick="searchListForm();"><spring:message code="commom_check"/></button>
                    <button type="button"  onclick="clean();"><spring:message code="material_reset"/></button>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="material:stock:edit">
                    <button type="button" onclick="popup('900px','800px','${ctx}/material/stock/form?winFlag=1')"><spring:message code="material_create"/></button>
                    </shiro:hasPermission>
                </div>
            </div>
    
       <div class="tableArea">
				<div class="tableScrollSm" style="overflow: auto;width: 1538px;height: 714px; ">
                    <table cellpadding="0" class="tableHead">
                        <thead>
                            <tr>
	                            <!-- 序号No. -->
	                            <th><p class="width-50px"><spring:message code="common_no"/></p></th>
	                            <!-- 物料图片 -->
	                            <th><p class="width-80px"><spring:message code="material_pic"/></p></th>
	                            <!-- 编码/物料名称 -->
	                            <th><p class="width-125px"><spring:message code="material_code_name"/></p></th>
	                            <%-- <!-- 业务类别 -->
	                            <th><p class="width-100px"><spring:message code="material_businessType"/></p></th> --%>
	                            <!-- 客户 -->
	                            <th><p class="width-100px"><spring:message code="material_showMateial_ognizationList"/></p></th>
	                            <!-- 客户品牌 -->
	                            <th><p class="width-100px"><spring:message code="material_showMateial_brandName"/></p></th>
	                            <!-- 物料类别 -->
	                            <th><p class="width-80px"><spring:message code="material_materialType"/></p></th>
	                            <!-- 幅宽 -->
	                            <th><p class="width-70px"><spring:message code="material_spec"/></p></th>
	                            <!-- 克重 -->
	                            <th><p class="width-70px"><spring:message code="material_gramWeight"/></p></th>
	                            <!-- 纱织密度 -->
	                            <th><p class="width-80px"><spring:message code="material_threadCount"/></p></th>
	                            <!-- 物料成分 -->
	                            <th><p class="width-80px"><spring:message code="material_composition"/></p></th>
	                            <!-- 物料风格 -->
	                            <th><p class="width-80px"><spring:message code="material_style"/></p></th>
	                            <!-- 物料颜色 -->
	                            <th><p class="width-80px"><spring:message code="material_color"/></p></th>
	                            <!-- 物料织法 -->
	                            <th><p class="width-80px"><spring:message code="material_knitMethod"/></p></th>
	                            <%-- <!-- 季节年份 -->
	                            <th><p class="width-80px"><spring:message code="material_seasonAndYear"/></p></th> --%>	 
	                            <!-- 描述 -->
	                            <th><p class="width-125px"><spring:message code="material_remarks"/></p></th>                           
	                            <!-- 供货商 -->
	                            <th><p class="width-100px"><spring:message code="material_showMateial_supplierName"/></p></th>
	                            <%-- <!-- 物料所属 -->
	                            <th><p class="width-80px"><spring:message code="material_showMateial_materialBelongs"/></p></th> --%>
	                            <!-- 库存数量 -->
	                            <th><p class="width-100px"><spring:message code="material_Inventory_quantity"/></p></th>
	                            <!-- 库存预警数量 -->
	                            <th><p class="width-100px"><spring:message code="material_Inventory_alert_quantity"/></p></th>
                            </tr>
                        </thead>
                    </table>
                    <table cellpadding="0" class="tableBody">
					    <tbody  id = "listHtml"></tbody>	
                	</table>
            	</div>
        	</div>
        	
		</div>
        <div id = "paging" ></div>
      </div>
      </form>
    </body>
</html>